⬡ Hub
Skip to content

Project 4: Variational Quantum Eigensolver (VQE) on a Molecule

Description

The Variational Quantum Eigensolver (VQE) is a hybrid quantum-classical algorithm used to find the ground state energy of a molecule, a fundamental problem in quantum chemistry. It uses a quantum computer to prepare a trial wavefunction and a classical computer to optimize the parameters of the wavefunction.

Objectives

  • Understand the basics of quantum chemistry and the concept of a Hamiltonian.
  • Learn how to map a molecular Hamiltonian to a qubit Hamiltonian.
  • Implement the VQE algorithm to find the ground state energy of a simple molecule like H2 or LiH.

Implementation Details

  1. Frameworks: Use Qiskit (with the Qiskit Nature extension) or PennyLane.
  2. The Algorithm:
    • Define the Molecule: Specify the atoms and their coordinates.
    • Hamiltonian: Construct the molecular Hamiltonian, which represents the total energy of the molecule.
    • Ansatz: Choose a parameterized quantum circuit (an "ansatz") to prepare the trial wavefunction.
    • Optimization Loop:
      • The classical optimizer chooses a set of parameters for the ansatz.
      • The quantum computer executes the ansatz circuit and measures the energy.
      • The classical optimizer uses the measured energy to choose a new set of parameters.
    • Convergence: The loop continues until the energy converges to a minimum, which is an approximation of the ground state energy.
  3. Code Example (Qiskit Nature):
from qiskit_nature.drivers import PySCFDriver
from qiskit_nature.problems.second_quantization import ElectronicStructureProblem
from qiskit_nature.converters.second_quantization import QubitConverter
from qiskit_nature.mappers.second_quantization import JordanWignerMapper
from qiskit.algorithms import VQE
from qiskit.algorithms.optimizers import SPSA
from qiskit.circuit.library import TwoLocal
from qiskit import Aer

# Define the molecule (H2)
driver = PySCFDriver(atom='H .0 .0 .0; H .0 .0 0.735')
problem = ElectronicStructureProblem(driver)
qubit_converter = QubitConverter(mapper=JordanWignerMapper())

# Set up VQE
optimizer = SPSA(maxiter=100)
ansatz = TwoLocal(rotation_blocks='ry', entanglement_blocks='cz')
vqe = VQE(ansatz=ansatz, optimizer=optimizer, quantum_instance=Aer.get_backend('statevector_simulator'))

# Run VQE
result = vqe.compute_minimum_eigenvalue(operator=problem.second_q_ops()[0])
print(f"Ground state energy: {result.eigenvalue.real}")